<template>
  <div class="app-container">
    <!-- 查询表单-->
    <!--element-ui的 date-picker组件默认绑定的时间值是默认世界标准时间，和中国时间差8小时
          设置 value-format="yyyy-MM-dd HH:mm:ss" 改变绑定的值-->
    <div id="content">
      <i class="el-icon-menu">筛选</i>
      <p />
      <el-form :inline="true" :model="regularQuery" class="demo-form-inline">
        <el-form-item label="输入搜索">
          <el-input
            v-model="regularQuery.name"
            placeholder="输入图书名称"
          ></el-input>
        </el-form-item>
        <el-form-item label="创建时间">
          <el-date-picker
            v-model="regularQuery.startTime"
            type="datetime"
            placeholder="选择开始日期"
            default-time="00:00:00"
          />
        </el-form-item>
        <el-form-item>
          <el-date-picker
            v-model="regularQuery.endTime"
            type="datetime"
            placeholder="选择结束日期"
            default-time="00:00:00"
          />
        </el-form-item>
        <el-button type="primary" icon="el-icon-search" @click="getQueryList()"
          >筛选</el-button
        >
        <el-button type="default" @click="resetData()">清空筛选条件</el-button>
      </el-form>
      <el-row>
        <el-col
          ><div class="grid-content bg-purple">
            <i class="el-icon-menu">待审批列表</i>
          </div></el-col
        >
        <el-col><div class="grid-content bg-purple-light"></div></el-col>

        <el-col
          ><div class="grid-content bg-purple-light add">
            <router-link :to="{ path: '/list/recycleRegular' }">
              <el-button type="primary" icon="el-icon-delete"
                >审批不通过图书</el-button
              >
            </router-link>
          </div></el-col
        >
      </el-row>
      <p />
      <!--表格-->
      <el-table
        v-loading="listLoading"
        :data="booklist"
        @selection-change="handleSelectionChange"
        element-loading-text="数据加载中"
        border
        fit
        stripe
        highlight-current-row
        style="width: 100%"
      >
        <!--数据展示- class="head_pic"-->
        <el-table-column
          type="selection"
          width="65"
          align="center"
        ></el-table-column>
        <el-table-column prop="id" label="书籍id" width="80" align="center" />
        <el-table-column
          prop="bookName"
          label="书籍名称"
          width="160"
          align="center"
        >
        </el-table-column>
        <el-table-column label="封面" width="180" align="center">
          <template slot-scope="scope">
            　　　　<img :src="scope.row.image" width="40" height="40" />
            　　</template
          >
          ></el-table-column
        >
        
        <el-table-column
          prop="bookType"
          label="书籍类型"
          width="160"
          align="center"
        />
        <el-table-column
          prop="author"
          label="书籍作者"
          width="160"
          align="center"
        />
        <el-table-column
          prop="description"
          label="书籍简介"
          width="160"
          align="center"
        />
        <el-table-column
          prop="createTime"
          label="上传时间"
          width="160"
          align="center"
        />
       
      
        <el-table-column label="操作" width="400" align="center" fixed="right">
          <template slot-scope="scope">
            <router-link :to="'/bookInfo/'+ scope.row.id ">
              <el-button type="primary" size="mini" icon="el-icon-edit"
                >预览</el-button
              >
            </router-link>
           
              <el-button type="primary" size="mini" icon="el-icon-edit" 
               @click="approval(scope.row.id, 1)"
                >审批通过</el-button
              >
           
              <el-button type="primary" size="mini" icon="el-icon-edit"
               @click="approval(scope.row.id, 3)"
                >审批不通过</el-button
              >
           
        

        
            
          </template>
        </el-table-column>
      </el-table>

      <!-- 分页 -->
      <el-pagination
        :current-page="page"
        :page-size="limit"
        :total="total"
        background
        style="padding: 30px 0; text-align: center"
        layout="total, prev, pager, next, jumper"
        @current-change="getbooklist()"
      />
    </div>
  </div>
</template>
<script>
//引入调用slideShow.js文件
import regularApi from "@/api/regular";

export default {
  //写核心代码位置
  // data:{
  // },
  data() {
    //定义变量和初始值
    return {
      listLoading: true, // 是否显示loading信息
      booklist: null, //查询之后接口返回集合
      page: 1, //当前页
      limit: 10, //每页记录数
      total: 0, //总记录数
      regularQuery: {
        //条件封装对象
        bookId:"",
        bookName: "",
        startTime: "",
        endTime: "",
        page:1,
        limit:10 
      },
      checkList: [],
    };
  },
  created() {
   
  },
  mounted() {
     this.listLoading = false;
    //页面渲染之前执行，一般调用methods定义的方法
    //调用
    this.getbooklist();
  },
  methods: {
    //取消或者确定明星产品
    // updateIsHot(id, isHot) {
    //   this.regularQuery.isHot = isHot;
    //   this.regularQuery.fid = id;
    //   regularApi.updateIsHot(this.regularQuery).then((response) => {
    //     //提示信息
    //     this.$message({
    //       type: "success",
    //       message: "修改明星产品状态成功!",
    //     });
    //     if (response.code == 200) {
    //       //回到列表页面 路由跳转
    //       // this.$router.push({ path: "/list/regular" });
    //       this.getbooklist();
    //     }
    //   });
    // },
    //创建具体的方法，调用slideShow.js定义的方法
    //获取轮播图列表的方法,默认是第一页
    approval(bookId,status){
            this.$confirm(
        "此操作将会审批书籍,是否继续?",
        "提示",
        {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        }
      )
        .then(() => {
          console.log(bookId,status);
        regularApi.approval(bookId,status).then((response) => {
        //请求成功
        //response接口返回的数据
        if(status==3){
                    this.$message({
                    type: "success",
                    message: "已审批，未通过!",
                  });
        }
        if(status==1){
                    this.$message({
                    type: "success",
                    message: "已审批，通过!",
                  });
        }
         this.getbooklist();
              
      });
      });
    },
    getbooklist() {
      
      this.regularQuery.page = this.page;
      this.regularQuery.size = this.limit;
      regularApi.getbookListPage(this.regularQuery).then((response) => {
        //请求成功
        //response接口返回的数据
        this.booklist = response.data.list;
        console.log(this.list);
        this.total = response.data.total;
      });
    },
    getQueryList(page = 1) {
      this.page = page;
      this.regularQuery.page = this.page;
      this.regularQuery.size = this.limit;
      this.regularQuery.status = 1;
      regularApi.getQueryRegularListPage(this.regularQuery).then((response) => {
        console.log("数据,", response);
        //请求成功
        //response接口返回的数据
        this.booklist = response.data.list;
        this.total = response.data.total;
      });
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      //获取所有选中项的gh(工号)属性的值
      this.checkList = selection.map((item) => item.fid);
    },
    resetData() {
      //清空的方法
      //表单输入项数据清空
      this.regularQuery = {};
      this.checkList = [];
      //查询所有讲师数据
      this.getbooklist();
      this.$message({
        type: "success",
        message: "清空成功!",
      });
    },
    //下架产品的方法
    removeDataById(id) {
      this.checkList.push(id);
      this.$confirm(
        "此操作将会下架产品,是否继续?",
        "提示",

        {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        }
      )
        .then(() => {
          //点击确定，执行then方法
          //调用删除的方法
          regularApi.removeRegular(this.checkList).then((response) => {
            //删除成功
            //提示信息
            this.checkList = [];
            this.$message({
              type: "success",
              message: "产品下架成功!",
            });
            //回到列表页面
            // this.$router.push({ path: "/list/slideShow" });
            this.getbooklist();
          });
        })
        .catch((e) => {
          this.checkList = [];
          this.$message({
            type: "info",
            message: "已取消下架操作!",
          });
        }); //点击取消，执行catch方法
    },
  },
};
</script>
<style>
#content {
  width: 80%;
  margin: 0 auto;
}
.el-row .el-col-24 {
  width: 250px;
}
.el-col-24:nth-child(3),
.el-col-24:nth-child(4) {
  float: right;
}
</style>